<template>
    <div>
        <!--:model="shop" 数据双向绑定-->
        <!--ref="shopForm" id="shopForm",给form去一个名字-->
        <!--:rules="formRules" 校验规则-->
        <el-form :model="shop" ref="shopForm" :rules="formRules" label-position="left" label-width="100px"
                 class="demo-ruleForm login-container">
            <h3 class="title">店铺入驻</h3>
            <el-form-item prop="shop.name" label="名称">
                <el-input type="text" v-model="shop.shop.name" auto-complete="off" placeholder="请输入店铺名称！"></el-input>
            </el-form-item>
            <el-form-item prop="tel" label="座机">
                <el-input type="text" v-model="shop.shop.tel" auto-complete="off" placeholder="请输入座机！"></el-input>
            </el-form-item>
            <el-form-item prop="address" label="店铺地址">
                <el-input type="text" v-model="shop.shop.address" auto-complete="off" placeholder="请输入地址！"></el-input>
                <!--        <el-button size="small" type="primary" @click="selectAdrress">选择</el-button>-->
            </el-form-item>
            <el-form-item prop="logo" label="店铺Logo">
                <el-upload
                        name="file1"
                        class="avatar-uploader"
                        action="http://localhost:80/file/upload"
                        :show-file-list="false"
                        :on-success="handleAvatarSuccess"
                        :before-upload="beforeAvatarUpload">
                    <img v-if="imageUrl" :src="imageUrl" class="avatar">
                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
            </el-form-item>
            <h3 class="title">管理员信息设置</h3>
            <el-form-item prop="username" label="账号">
                <el-input type="text" v-model="shop.employee.username" auto-complete="off"
                          placeholder="请输入账号！"></el-input>
            </el-form-item>
            <el-form-item prop="phone" label="手机号码">
                <el-input type="text" v-model="shop.employee.phone" auto-complete="off" placeholder="请输入电话！"></el-input>
            </el-form-item>
            <el-form-item prop="email" label="电子邮件">
                <el-input type="text" v-model="shop.employee.email" auto-complete="off" placeholder="请输入邮件！"></el-input>
            </el-form-item>
            <el-form-item prop="password" label="密码">
                <el-input type="password" v-model="shop.employee.password" auto-complete="off"
                          placeholder="请输入密码！"></el-input>
            </el-form-item>
            <el-form-item prop="comfirmPassword" label="确认密码">
                <el-input type="password" v-model="shop.employee.comfirmPassword" auto-complete="off"
                          placeholder="请输入确认密码！"></el-input>
            </el-form-item>
            <el-form-item style="width:100%;">
                <el-button type="primary" style="width:100%;" @click.native.prevent="onSubmit">入驻</el-button>
            </el-form-item>
        </el-form>
        <el-dialog
                title="选择地址"
                :visible.sync="dialogVisable"
                width="30%">
            <!--<baidu-map :center="{lng: 116.403765, lat: 39.914850}" :zoom="11">
                <bm-view class="map"></bm-view>
                <bm-control :offset="{width: '10px', height: '10px'}">
                    &lt;!&ndash;:sugStyle="{zIndex: 2100} 让搜索提示上浮&ndash;&gt;
                    <bm-auto-complete v-model="keyword" :sugStyle="{zIndex: 2100}">
                        <div style="margin-bottom:10px">
                            <input id="searchInput" type="text" placeholder="请输入关键字" class="searchinput"/>
                            <el-button type="success" @click="selectAdrressConfirm">确定</el-button>
                        </div>
                    </bm-auto-complete>
                </bm-control>
                <bm-local-search :keyword="keyword" :auto-viewport="true" ></bm-local-search>
            </baidu-map>-->
            <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisable=false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible=true">确 定</el-button>
      </span>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                imageUrl: '',
                dialogVisable: false,
                shop: {
                    employee: {

                    },
                    shop: {
                    }
                }, //这个参数用于保存需要提交到后台的所有参数信息
                formRules: {
                    //required:设置当前属性是否必填;message:如果不满足条件,将提示的文本信息;trigger:触发的事件:blur:失去焦点
                  'shop.name': [
                        {required: true, message: '请输入活动名称', trigger: 'blur'}
                    ]
                }
            }
        },
        methods: {
            handleAvatarSuccess(res, file) {//res就是上传成功后，后台返回的结果
                console.log(JSON.stringify(res));
                this.imageUrl = res;
                //将图片的真实地址赋值给shop实体类中的logo属性
                this.shop.shop.logo = res;
            },
            // 这个方法是在：用户选择了上传的文件后&执行上传操作之前   两者之间触发
            beforeAvatarUpload(file) {//该方法主要用于：判断选择上传的文件格式&大小 ，是否满足要求
                const isJPG = file.type === 'image/jpeg';
                const isLt2M = file.size / 1024 / 1024 < 2;

                if (!isJPG) {
                    this.$message.error('上传头像图片只能是 JPG 格式!');
                }
                if (!isLt2M) {
                    this.$message.error('上传头像图片大小不能超过 2MB!');
                }
                return isJPG && isLt2M;
            },

            onSubmit() {
              console.log(">>>>>"+JSON.stringify(this.shop))
                //发送请求
                this.$http.post("/shop/register", this.shop).then(res => {
                    if (res.data.success){
                        //直接跳转到首页
                        this.$router.push('/login');
                    }else {
                      this.$message.error(res.data.message);
                    }
                })
            }
        },
        mounted() {

        }
    }

</script>
<style lang="scss" scoped>

    .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }
    .avatar-uploader .el-upload:hover {
        border-color: #409EFF;
    }
    .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 178px;
        height: 178px;
        line-height: 178px;
        text-align: center;
    }
    .avatar {
        width: 178px;
        height: 178px;
        display: block;
    }

    .login-container {
        -webkit-border-radius: 5px;
        border-radius: 5px;
        -moz-border-radius: 5px;
        background-clip: padding-box;
        margin: 180px auto;
        width: 500px;
        padding: 35px 35px 15px 35px;
        background: #fff;
        border: 1px solid #eaeaea;
        box-shadow: 0 0 25px #cac6c6;

        .title {
            margin: 0px auto 40px auto;
            text-align: center;
            color: #505458;
        }

        .remember {
            margin: 0px 0px 35px 0px;
        }
    }

    .map {
        width: 100%;
        height: 300px;
    }

    .searchinput {
        width: 300px;
        box-sizing: border-box;
        padding: 9px;
        border: 1px solid #dddee1;
        line-height: 20px;
        font-size: 16px;
        height: 38px;
        color: #333;
        position: relative;
        border-radius: 4px;
    }
</style>
